package com.project.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import gz.JiuzhenService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(value = {"*"},allowCredentials = "true")
public class JiuzhenController {

    @Reference
    private JiuzhenService js;


    /**
     * 查询出所有未就诊的患者且进行模糊查询
     * @param name
     * @return
     */
    @RequestMapping("jzlb/queryPatient")
    public  List<Map<String,Object>> all(String name){
        System.out.println("传回来的参数"+name);
        List<Map<String,Object>> all = js.findAll(name);
        System.out.println("数据："+all);
        return all;
    }

    /**
     * 查询出已就诊的患者且根据患者姓名模糊查询
     * @param names
     * @return
     */
    @RequestMapping("jzlb/findAllStatus")
    public List<Map<String,Object>> alls(String names){
        System.out.println("传回来的参数"+names);
        List<Map<String,Object>> alls= js.findAlls(names);
        System.out.println("数据："+alls);
        return alls;
    }


    /**
     * 退号或作废操作，
     * @param request
     * @return
     */
    @RequestMapping("jzlb/updateRegStatus")
    public Map<String,Object> tuihao(HttpServletRequest request){
        //3为退号，4位作废
        String status1 = request.getParameter("status");
        String id1 = request.getParameter("registration_id");
        String ids = request.getParameter("patient_id");
        Integer status = Integer.valueOf(status1);
        Integer id = Integer.valueOf(id1);
        Integer patient_id = Integer.valueOf(ids);
        System.out.println("返回的状态："+status);
        System.out.println("返回的patient_id："+patient_id);
        System.out.println("返回的id:"+id);
        int i = js.updateIdStatus(id,status);
        System.out.println(i+"行受影响");
        Map<String,Object> map = new HashMap<>();
        if(i>0){
            map.put("msg","true");
        }else{
            map.put("msg","false");
        }
        return map;
    }


}
